home *** CD-ROM | disk | FTP | other *** search
- // mycloctl.cpp : Implementation of the CMyclockCtrl OLE control class.
-
- #include "stdafx.h"
- #include "myclock.h"
- #include "mycloctl.h"
- #include "mycloppg.h"
-
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
-
- IMPLEMENT_DYNCREATE(CMyclockCtrl, COleControl)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Message map
-
- BEGIN_MESSAGE_MAP(CMyclockCtrl, COleControl)
- //{{AFX_MSG_MAP(CMyclockCtrl)
- ON_WM_CREATE()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Dispatch map
-
- BEGIN_DISPATCH_MAP(CMyclockCtrl, COleControl)
- //{{AFX_DISPATCH_MAP(CMyclockCtrl)
- DISP_PROPERTY_NOTIFY(CMyclockCtrl, "UpdateInterval", m_updateInterval, OnUpdateIntervalChanged, VT_I4)
- DISP_FUNCTION(CMyclockCtrl, "Beep", Beep, VT_EMPTY, VTS_NONE)
- DISP_STOCKFUNC_REFRESH()
- DISP_STOCKPROP_BACKCOLOR()
- DISP_STOCKPROP_FORECOLOR()
- DISP_STOCKPROP_FONT()
- //}}AFX_DISPATCH_MAP
- DISP_FUNCTION_ID(CMyclockCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
- END_DISPATCH_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Event map
-
- BEGIN_EVENT_MAP(CMyclockCtrl, COleControl)
- //{{AFX_EVENT_MAP(CMyclockCtrl)
- EVENT_CUSTOM("NewMinute", FireNewMinute, VTS_NONE)
- EVENT_STOCK_CLICK()
- EVENT_STOCK_DBLCLICK()
- //}}AFX_EVENT_MAP
- END_EVENT_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Property pages
-
- // TODO: Add more property pages as needed. Remember to increase the count!
- BEGIN_PROPPAGEIDS(CMyclockCtrl, 3)
- PROPPAGEID(CMyclockPropPage::guid)
- PROPPAGEID(CLSID_CColorPropPage)
- PROPPAGEID(CLSID_CFontPropPage)
- END_PROPPAGEIDS(CMyclockCtrl)
-
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Initialize class factory and guid
-
- IMPLEMENT_OLECREATE_EX(CMyclockCtrl, "MYCLOCK.MyclockCtrl.1",
- 0x85a87840, 0xd415, 0x101b, 0x96, 0xe3, 0x0, 0x20, 0xaf, 0x38, 0xf4, 0xbb)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Type library ID and version
-
- IMPLEMENT_OLETYPELIB(CMyclockCtrl, _tlid, _wVerMajor, _wVerMinor)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Interface IDs
-
- const IID BASED_CODE IID_DMyclock =
- { 0x85a87841, 0xd415, 0x101b, { 0x96, 0xe3, 0x0, 0x20, 0xaf, 0x38, 0xf4, 0xbb } };
- const IID BASED_CODE IID_DMyclockEvents =
- { 0x85a87842, 0xd415, 0x101b, { 0x96, 0xe3, 0x0, 0x20, 0xaf, 0x38, 0xf4, 0xbb } };
-
-
- /////////////////////////////////////////////////////////////////////////////
- // Control type information
-
- static const DWORD BASED_CODE _dwMyclockOleMisc =
- OLEMISC_ACTIVATEWHENVISIBLE |
- OLEMISC_SETCLIENTSITEFIRST |
- OLEMISC_INSIDEOUT |
- OLEMISC_CANTLINKINSIDE |
- OLEMISC_RECOMPOSEONRESIZE;
-
- IMPLEMENT_OLECTLTYPE(CMyclockCtrl, IDS_MYCLOCK, _dwMyclockOleMisc)
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyclockCtrl::CMyclockCtrlFactory::UpdateRegistry -
- // Adds or removes system registry entries for CMyclockCtrl
-
- BOOL CMyclockCtrl::CMyclockCtrlFactory::UpdateRegistry(BOOL bRegister)
- {
- if (bRegister)
- return AfxOleRegisterControlClass(
- AfxGetInstanceHandle(),
- m_clsid,
- m_lpszProgID,
- IDS_MYCLOCK,
- IDB_MYCLOCK,
- FALSE, // Not insertable
- _dwMyclockOleMisc,
- _tlid,
- _wVerMajor,
- _wVerMinor);
- else
- return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyclockCtrl::CMyclockCtrl - Constructor
-
- CMyclockCtrl::CMyclockCtrl()
- {
- InitializeIIDs(&IID_DMyclock, &IID_DMyclockEvents);
-
- // TODO: Initialize your control's instance data here.
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Set the initial size of the control to Width=200, Height=15.
- SetInitialSize(200, 15);
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyclockCtrl::~CMyclockCtrl - Destructor
-
- CMyclockCtrl::~CMyclockCtrl()
- {
- // TODO: Cleanup your control's instance data here.
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyclockCtrl::OnDraw - Drawing function
-
- void CMyclockCtrl::OnDraw(
- CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
- {
- // TODO: Replace the following code with your own drawing code.
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Select the font that is specified by the stock Font property.
- CFont* pOldFont = SelectStockFont(pdc);
-
- // Set the foreground color (i.e. the text color)
- // according to the ForeColor property.
- pdc->SetTextColor(TranslateColor(GetForeColor()));
-
- // Set the background mode to transparent mode.
- pdc->SetBkMode(TRANSPARENT);
-
- // Create a brush based on the BackColor property.
- CBrush bkBrush(TranslateColor(GetBackColor()));
-
- // Paint the background using the BackColor property
- pdc->FillRect(rcBounds, &bkBrush);
-
- char CurrentTime[30];
- struct tm *newtime;
- long lTime;
-
- // Get the current time
- time(&lTime);
- newtime=localtime(&lTime);
-
- // Convert the time into a string.
- strcpy(CurrentTime, asctime(newtime));
-
- // Pad the string with 1 blank.
- CurrentTime[24]=' ';
-
- // Terminate the string.
- CurrentTime[25] = 0;
-
- // Display the current time
- pdc->ExtTextOut(rcBounds.left,
- rcBounds.top,
- ETO_CLIPPED,
- rcBounds,
- CurrentTime,
- strlen(CurrentTime),
- NULL);
-
- // Select the original font.
- pdc->SelectObject(pOldFont);
-
-
- // If new minute has just begun, fire a NewMinute event.
- if (newtime->tm_sec==0)
- FireNewMinute();
-
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyclockCtrl::DoPropExchange - Persistence support
-
- void CMyclockCtrl::DoPropExchange(CPropExchange* pPX)
- {
- ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
- COleControl::DoPropExchange(pPX);
-
- // TODO: Call PX_ functions for each persistent custom property.
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Initialize the UpdateInterval property to 1000.
- PX_Long( pPX, _T("UpdateIntrval"), m_updateInterval, 1000L );
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyclockCtrl::OnResetState - Reset control to default state
-
- void CMyclockCtrl::OnResetState()
- {
- COleControl::OnResetState(); // Resets defaults found in DoPropExchange
-
- // TODO: Reset any other control state here.
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyclockCtrl::AboutBox - Display an "About" box to the user
-
- void CMyclockCtrl::AboutBox()
- {
- CDialog dlgAbout(IDD_ABOUTBOX_MYCLOCK);
- dlgAbout.DoModal();
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyclockCtrl message handlers
-
- int CMyclockCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (COleControl::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // TODO: Add your specialized creation code here
-
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Install a timer.
- SetTimer(1, (UINT)m_updateInterval, NULL);
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- return 0;
- }
-
- void CMyclockCtrl::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Trigger a call to the OnDraw() function.
- InvalidateControl();
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- COleControl::OnTimer(nIDEvent);
- }
-
- void CMyclockCtrl::OnUpdateIntervalChanged()
- {
- // TODO: Add notification handler code
-
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Make sure the user did not set the property to a
- // negative value.
- if (m_updateInterval < 0)
- {
- MessageBox("This property cannot be negative!");
- m_updateInterval = 1000;
- }
-
- // Re-install the timer with interval set
- // to the current value of the UpdateInterval
- // property.
- SetTimer(1, (UINT)m_updateInterval, NULL);
-
-
- SetModifiedFlag();
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- }
-
-
- void CMyclockCtrl::Beep()
- {
- // TODO: Add your dispatch handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- MessageBeep((WORD)-1);
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-